package cn.org.itool.ws;

import cn.org.itool.ws.framework.ws.WsServer;
import jakarta.annotation.Resource;
import lombok.extern.log4j.Log4j2;
import org.springframework.context.SmartLifecycle;
import org.springframework.stereotype.Component;

@Log4j2
@Component
public class WsApplication  implements SmartLifecycle{

    public static void main(String[] args) {

    }

    private volatile boolean running = false;

    @Resource
    private WsServer wsServer;

    @Override
    public void start() {
        log.info("-boot start-------------------");

        running = true;
        // 执行启动逻辑

        wsServer.start();
    }

    @Override
    public void stop() {
        running = false;
        // 执行停止逻辑
        wsServer.stop();
        log.info("-boot stop-------------------");
    }

    @Override
    public boolean isRunning() {
        return running;
    }

    @Override
    public int getPhase() {
        return Integer.MAX_VALUE; // 设置最高优先级，保证在停止时最后执行
    }

}
